package com.yjt.fresh.api;

import android.app.Activity;

import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseApi;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.listener.HttpOnNextListener;
import com.yjt.fresh.httpservice.HttpPostService;
import com.yjt.fresh.utils.PreferenceManager;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Retrofit;
import rx.Observable;

/**
 * 3.8.	3.69.	上传图片-通用
 * Created by WZG on 2016/7/16.
 */
public class ApiImageUpload extends BaseApi {

    /*需要上传的文件*/
    private MultipartBody.Part part;

    public ApiImageUpload(HttpOnNextListener listener, Activity rxAppCompatActivity, boolean showProgress, boolean cache, boolean cancel) {
        super(listener, rxAppCompatActivity, showProgress, cache, cancel);
    }


    public MultipartBody.Part getPart() {
        return part;
    }

    public void setPart(MultipartBody.Part part) {
        this.part = part;
    }


    @Override
    public Observable getObservable(Retrofit retrofit) {
        HttpPostService service = retrofit.create(HttpPostService.class);
        RequestBody session_id= RequestBody.create(MediaType.parse("text/plain"), PreferenceManager.getInstance().getUserInfo().getSESSION_ID());
        return service.imgUpload(getPart(),session_id);
    }
}
